package com.tledu.network;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GetNetworkData {
    public static void main(String[] args) throws IOException {
        String baidu = "https://www.baidu.com/";
        // 获取对URL的封装类
        URL url = new URL(baidu);
        // 打开url连接
        URLConnection urlConnection = url.openConnection();
        // 通过io流获取数据
        InputStream in = urlConnection.getInputStream();
        // 转换
        InputStreamReader reader = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(reader);
        // 读取数据
        String result = "";
        while (true) {
            String line = br.readLine();
            if (line == null) {
                break;
            }
            result += line;
        }
        br.close();
        System.out.print(result);
    }
}
